package com.mlh.springboot.config;

import com.mlh.springboot.servlet.MyFilter;
import com.mlh.springboot.servlet.MyListener;
import com.mlh.springboot.servlet.MyServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.print.DocFlavor;
import java.util.Arrays;

/**
 * @author 缪林辉
 * @date 2024/3/3 21:00
 * @DESCRIPTION
 */
@Configuration(proxyBeanMethods = true)
public class MyRegisterConfig {
    @Bean
    public ServletRegistrationBean servletRegistrationBean(){
        MyServlet myServlet = new MyServlet();
        return new ServletRegistrationBean(myServlet,"/servlet01","/servlet02");
    }
    @Bean
    public FilterRegistrationBean filterRegistrationBean(){
        MyFilter myFilter = new MyFilter();
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(myFilter);
        //Arrays.asList 该方法是将数组转化成List集合的方法。
        filterRegistrationBean.setUrlPatterns(Arrays.asList("/images/*", "/css/*"));
        return filterRegistrationBean;
    }
    @Bean
    public ServletListenerRegistrationBean servletListenerRegistrationBean(){
        MyListener myListener = new MyListener();
        return new ServletListenerRegistrationBean(myListener);
    }
}
